﻿<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site.Master" CodeBehind="ProductDetail.aspx.vb" Inherits="FishTank.ProductDetail" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<asp:FormView ID="DetailFormView" runat="server" width="100%" CssClass="detailView">
            <EditItemTemplate>
                <h1>Edit product</h1>

                <span class="failureNotification">
                    <asp:Literal ID="FailureText" runat="server"></asp:Literal>
                </span>
                <asp:ValidationSummary ID="ProductInfoValidationSummary" runat="server" CssClass="failureNotification" 
                     ValidationGroup="ProductInfoValidationGroup"/>

                <div class="itemInfo">
                <fieldset class="item">
                    <legend>Product Information</legend>
                    <p>
                        <asp:Label ID="ModelLabel" runat="server" AssociatedControlID="ModelTextBox">Model:</asp:Label>
                        <asp:TextBox ID="ModelTextBox" runat="server" CssClass="textEntry" Text='<%# Bind("Model") %>'></asp:TextBox>
                        <asp:RequiredFieldValidator ID="ModelRequiredValidator" runat="server" ControlToValidate="ModelTextBox" 
                             CssClass="failureNotification" ErrorMessage="Model is required." ToolTip="Model is required." 
                             ValidationGroup="ProductInfoValidationGroup">*</asp:RequiredFieldValidator>
                    </p>
                    <p>
                        <asp:Label ID="ManufacturerLabel" runat="server" AssociatedControlID="ManufacturerTextBox">Manufacturer:</asp:Label>
                        <asp:TextBox ID="ManufacturerTextBox" runat="server" CssClass="textEntry" Text='<%# Bind("Manufacturer") %>'></asp:TextBox>
                        <asp:RequiredFieldValidator ID="ManufacturerRequiredValidator" runat="server" ControlToValidate="ManufacturerTextBox" 
                             CssClass="failureNotification" ErrorMessage="Manufacturer is required." ToolTip="Manufacturer is required." 
                             ValidationGroup="ProductInfoValidationGroup">*</asp:RequiredFieldValidator>
                    </p>
                    <p>
                        <asp:Label ID="WebsiteLabel" runat="server" AssociatedControlID="WebsiteTextBox">Website:</asp:Label>
                        <asp:TextBox ID="WebsiteTextBox" runat="server" CssClass="textEntry" Text='<%# Bind("URL") %>'></asp:TextBox>
                        <asp:RegularExpressionValidator ID="WebsiteURLValidator" runat="server"   
                            ValidationExpression="http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?"  
                            ControlToValidate="WebsiteTextBox" ErrorMessage="Website URL is not valid."
                            ValidationGroup="ProductInfoValidationGroup" Display="None"></asp:RegularExpressionValidator>  
                    </p>
                    <p class="textBody">
                        Length: 
                        <asp:TextBox ID="LengthTextBox" runat="server" Width="32" Text='<%# Bind("Length") %>'></asp:TextBox>
                        <asp:RequiredFieldValidator ID="LengthRequiredValidator" runat="server" ControlToValidate="LengthTextBox" 
                            CssClass="failureNotification" ErrorMessage="Length is required." ToolTip="Length is required." 
                            ValidationGroup="ProductInfoValidationGroup">*</asp:RequiredFieldValidator>cm
                        <asp:RangeValidator ID="LengthRangeValidator" runat="server" ControlToValidate="LengthTextBox" 
                            ErrorMessage="Length minimum value is 1 and maximum is 1000" 
                            MinimumValue="1" MaximumValue="1000" Type="Integer"
                            Display="None" ValidationGroup="ProductInfoValidationGroup" ></asp:RangeValidator>
                        <asp:CompareValidator ID="LengthNumberValidator" runat="server" 
                            ControlToValidate="LengthTextBox" Display="None"
                            ErrorMessage="Length is not an integer"
                            Operator="DataTypeCheck" Type="Integer"
                            ValidationGroup="ProductInfoValidationGroup"></asp:CompareValidator>

                        Height:
                        <asp:TextBox ID="HeightTextBox" runat="server" Width="32" Text='<%# Bind("Height") %>'></asp:TextBox>
                        <asp:RequiredFieldValidator ID="HeightRequiredValidator" runat="server" ControlToValidate="HeightTextBox" 
                            CssClass="failureNotification" ErrorMessage="Height is required." ToolTip="Height is required." 
                            ValidationGroup="ProductInfoValidationGroup">*</asp:RequiredFieldValidator>cm
                        <asp:RangeValidator ID="HeightRangeValidator" runat="server" ControlToValidate="HeightTextBox" 
                            ErrorMessage="Height minimum value is 1 and maximum is 1000"
                            MinimumValue="1" MaximumValue="1000" Type="Integer"
                            Display="None" ValidationGroup="ProductInfoValidationGroup"></asp:RangeValidator>
                        <asp:CompareValidator ID="HeightNumberValidator" runat="server" 
                            ControlToValidate="HeightTextBox" Display="None"
                            ErrorMessage="Height is not an integer"
                            Operator="DataTypeCheck" Type="Integer"
                            ValidationGroup="ProductInfoValidationGroup"></asp:CompareValidator>

                        Width:
                        <asp:TextBox ID="WidthTextBox" runat="server" Width="32" Text='<%# Bind("Width") %>'></asp:TextBox>
                        <asp:RequiredFieldValidator ID="WidthRequiredValidator" runat="server" ControlToValidate="WidthTextBox" 
                            CssClass="failureNotification" ErrorMessage="Width is required." ToolTip="Width is required." 
                            ValidationGroup="ProductInfoValidationGroup">*</asp:RequiredFieldValidator>cm
                        <asp:RangeValidator ID="WidthRangeValidator" runat="server" ControlToValidate="WidthTextBox" 
                            ErrorMessage="Width minimum value is 1 and maximum is 1000"
                            MinimumValue="1" MaximumValue="1000" Type="Integer"
                            Display="None" ValidationGroup="ProductInfoValidationGroup"></asp:RangeValidator>
                        <asp:CompareValidator ID="WidthNumberValidator" runat="server" 
                            ControlToValidate="WidthTextBox" Display="None"
                            ErrorMessage="Width is not an integer"
                            Operator="DataTypeCheck" Type="Integer"
                            ValidationGroup="ProductInfoValidationGroup"></asp:CompareValidator>
                    </p>
                </fieldset>
                <p class="submitButton">
                    <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Cancel" 
                        ValidationGroup="ProductInfoValidationGroup" CausesValidation="False"
                        onclick="CancelEditButton_Click"/>
                    <asp:Button ID="SaveButton" runat="server" CommandName="Save" Text="Save" 
                        ValidationGroup="ProductInfoValidationGroup" onclick="SaveButton_Click"/>
                </p>
                </div>
            </EditItemTemplate>
            <InsertItemTemplate>
                <h1>Add a product</h1>

                <span class="failureNotification">
                    <asp:Literal ID="FailureText" runat="server"></asp:Literal>
                </span>
                <asp:ValidationSummary ID="ProductInfoValidationSummary" runat="server" CssClass="failureNotification" 
                     ValidationGroup="ProductInfoValidationGroup"/>

                <div class="itemInfo">
                <fieldset class="item">
                    <legend>Product Information</legend>
                    <p>
                        <asp:Label ID="ModelLabel" runat="server" AssociatedControlID="ModelTextBox">Model:</asp:Label>
                        <asp:TextBox ID="ModelTextBox" runat="server" CssClass="textEntry"></asp:TextBox>
                        <asp:RequiredFieldValidator ID="ModelRequiredValidator" runat="server" ControlToValidate="ModelTextBox" 
                             CssClass="failureNotification" ErrorMessage="Model is required." ToolTip="Model is required." 
                             ValidationGroup="ProductInfoValidationGroup">*</asp:RequiredFieldValidator>
                    </p>
                    <p>
                        <asp:Label ID="ManufacturerLabel" runat="server" AssociatedControlID="ManufacturerTextBox">Manufacturer:</asp:Label>
                        <asp:TextBox ID="ManufacturerTextBox" runat="server" CssClass="textEntry"></asp:TextBox>
                        <asp:RequiredFieldValidator ID="ManufacturerRequiredValidator" runat="server" ControlToValidate="ManufacturerTextBox" 
                             CssClass="failureNotification" ErrorMessage="Manufacturer is required." ToolTip="Manufacturer is required." 
                             ValidationGroup="ProductInfoValidationGroup">*</asp:RequiredFieldValidator>
                    </p>
                    <p>
                        <asp:Label ID="WebsiteLabel" runat="server" AssociatedControlID="WebsiteTextBox">Website:</asp:Label>
                        <asp:TextBox ID="WebsiteTextBox" runat="server" CssClass="textEntry"></asp:TextBox>
                        <asp:RegularExpressionValidator ID="WebsiteURLValidator" runat="server"   
                            ValidationExpression="http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?"  
                            ControlToValidate="WebsiteTextBox" ErrorMessage="Website URL is not valid."
                            ValidationGroup="ProductInfoValidationGroup" Display="None"></asp:RegularExpressionValidator>  
                    </p>
                    <p class="textBody">
                        Length: 
                        <asp:TextBox ID="LengthTextBox" runat="server" Width="32"></asp:TextBox>
                        <asp:RequiredFieldValidator ID="LengthRequiredValidator" runat="server" ControlToValidate="LengthTextBox" 
                            CssClass="failureNotification" ErrorMessage="Length is required." ToolTip="Length is required." 
                            ValidationGroup="ProductInfoValidationGroup">*</asp:RequiredFieldValidator>cm
                        <asp:RangeValidator ID="LengthRangeValidator" runat="server" ControlToValidate="LengthTextBox" 
                            ErrorMessage="Length minimum value is 1 and maximum is 1000" 
                            MinimumValue="1" MaximumValue="1000" Type="Integer"
                            Display="None" ValidationGroup="ProductInfoValidationGroup" ></asp:RangeValidator>
                        <asp:CompareValidator ID="LengthNumberValidator" runat="server" 
                            ControlToValidate="LengthTextBox" Display="None"
                            ErrorMessage="Length is not an integer"
                            Operator="DataTypeCheck" Type="Integer"
                            ValidationGroup="ProductInfoValidationGroup"></asp:CompareValidator>

                        Height:
                        <asp:TextBox ID="HeightTextBox" runat="server" Width="32"></asp:TextBox>
                        <asp:RequiredFieldValidator ID="HeightRequiredValidator" runat="server" ControlToValidate="HeightTextBox" 
                            CssClass="failureNotification" ErrorMessage="Height is required." ToolTip="Height is required." 
                            ValidationGroup="ProductInfoValidationGroup">*</asp:RequiredFieldValidator>cm
                        <asp:RangeValidator ID="HeightRangeValidator" runat="server" ControlToValidate="HeightTextBox" 
                            ErrorMessage="Height minimum value is 1 and maximum is 1000"
                            MinimumValue="1" MaximumValue="1000" Type="Integer"
                            Display="None" ValidationGroup="ProductInfoValidationGroup"></asp:RangeValidator>
                        <asp:CompareValidator ID="HeightNumberValidator" runat="server" 
                            ControlToValidate="HeightTextBox" Display="None"
                            ErrorMessage="Height is not an integer"
                            Operator="DataTypeCheck" Type="Integer"
                            ValidationGroup="ProductInfoValidationGroup"></asp:CompareValidator>

                        Width:
                        <asp:TextBox ID="WidthTextBox" runat="server" Width="32"></asp:TextBox>
                        <asp:RequiredFieldValidator ID="WidthRequiredValidator" runat="server" ControlToValidate="WidthTextBox" 
                            CssClass="failureNotification" ErrorMessage="Width is required." ToolTip="Width is required." 
                            ValidationGroup="ProductInfoValidationGroup">*</asp:RequiredFieldValidator>cm
                        <asp:RangeValidator ID="WidthRangeValidator" runat="server" ControlToValidate="WidthTextBox" 
                            ErrorMessage="Width minimum value is 1 and maximum is 1000"
                            MinimumValue="1" MaximumValue="1000" Type="Integer"
                            Display="None" ValidationGroup="ProductInfoValidationGroup"></asp:RangeValidator>
                        <asp:CompareValidator ID="WidthNumberValidator" runat="server" 
                            ControlToValidate="WidthTextBox" Display="None"
                            ErrorMessage="Width is not an integer"
                            Operator="DataTypeCheck" Type="Integer"
                            ValidationGroup="ProductInfoValidationGroup"></asp:CompareValidator>
                    </p>
                </fieldset>
                <p class="submitButton">
                    <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Cancel" 
                        ValidationGroup="ProductInfoValidationGroup" CausesValidation="False"
                        PostBackUrl="~/Pages/ProductList.aspx" />
                    <asp:Button ID="SubmitButton" runat="server" CommandName="Submit" Text="Submit" 
                        ValidationGroup="ProductInfoValidationGroup" onclick="SubmitButton_Click"/>
                </p>
                </div>
            </InsertItemTemplate>
            <ItemTemplate>
                <h1><asp:Label ID="TitleLabel" runat="server" Text="<%# Bind('Title') %>"></asp:Label></h1>

                <p class="author">
                    by
                    <a href="/Pages/MemberDetail.aspx?UserName=<%# Eval("MemberUserName") %>">
                        <asp:Label ID="MemberLabel" runat="server" Text='<%# Bind("MemberFullName") %>' />
                    </a>
                    at
                    <asp:Label ID="CreatedDateLabel" runat="server" Text='<%# Bind("CreatedDateTime", "{0:MMMM d, yyyy}") %>' />
                </p>

                <h3>Dimensions</h3>

                <dl>
                    <dt>Length</dt>
                        <dd><asp:Label ID="LengthLabel" runat="server" Text='<%# Bind("Length") %>' />cm</dd>
                    <dt>Height</dt>
                        <dd><asp:Label ID="HeightLabel" runat="server" Text='<%# Bind("Height") %>' />cm</dd>
                    <dt>Width</dt>
                        <dd> <asp:Label ID="WidthLabel" runat="server" Text='<%# Bind("Width") %>' />cm</dd>
                </dl>   

                <asp:Panel ID="WebsitePanel" runat="server"
                               Visible='<%# Not String.IsNullOrWhiteSpace(Convert.ToString(Eval("URL"))) %>'>
                    <p>
                        More info at
                        <asp:HyperLink ID="ProductHyperLink" runat="server" 
                                       NavigateUrl='<%# Eval("Url") %>'
                                       Text='<%# Eval("Url") %>' />
                    </p>
                </asp:Panel>
   
                <p class="submitButton">
                    <asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="Delete" 
                                onclick="DeleteButton_Click" Visible="<%# ModificationPermitted() %>"/>
                    <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" 
                                onclick="EditButton_Click" Visible="<%# ModificationPermitted() %>"/>
                </p>  
            </ItemTemplate>
        </asp:FormView>
</asp:Content>
